<?php
/**
 * Created by PhpStorm.
 * Project: HttpClient
 * User: jimcy
 * Date: 2019-01-31
 * Time: 21:44
 */

namespace HttpClient\TestHttpClient;


use PHPUnit\Framework\TestCase;
use Agoni\Dispatch;

//模拟测试
class TestDaDa extends TestCase
{
    protected $dispatch=null;

    public function __construct(string $name = null, array $data = [], string $dataName = '')
    {
        $this->dispatch = new Dispatch([
            'app_key' => 'xxxxxx',
            'secret' => 'xxxxxx',
            'source_id' => '73753',
        ]);
        parent::__construct($name, $data, $dataName);
    }
    /**
     * 添加订单
     */
    public function testAddOrder()
    {
        $data['shop_no'] = 11047059;
        $data['origin_id'] = "132132132141242141423123";
        $data['city_code'] = "029";
        $data['cargo_price'] = "11.2";
        $data['is_prepay'] = 0;
        $data['expected_fetch_time'] = time() + 3600;
        $data['receiver_name'] = "测试达达";
        $data['receiver_address'] = "上海市崇明岛";
        $data['receiver_phone'] = "11111111111";
        $data['receiver_lat'] = 31.63;
        $data['receiver_lng'] = 121.41;
        $data['callback'] = "http://test.agoni.com/web/index.php?r=api/delivery/delivery-call-back/index";
        $this->dispatch->methond('DaDa')->addOrder($data);
        $this->assertTrue(true);
    }
    ///模拟回调

    /**
     * 模拟接单
     */
    public function  testAcceptOrder(){
        $data['order_id']="DaDa20191118190151879711";
        $this->dispatch->methond('DaDa')->test->acceptOrder($data);
    }

    /**
     * 模拟完成取货
     */
    public function testFetchOrder(){
        $data['order_id']="DaDa20191118190151879711";
        $this->dispatch->methond('DaDa')->test->fetchOrder($data);
    }

    /**
     * 模拟完成订单
     */
    public function testFinish(){
        $data['order_id']="DaDa20191118190151879711";
        $this->dispatch->methond('DaDa')->test->finishOrder($data);
    }

    /**
     * 模拟取消订单
     */
    public function testCancelOrder(){
        $data['order_id']="132132132141242141423123";
        $this->dispatch->methond('DaDa')->test->cancelOrder($data);
    }

    /**
     * 模拟异常订单返回
     */
    public function testAbnormalBack(){
        $data['order_id']="132132132141242141423123";
        $this->dispatch->methond('DaDa')->test->abnormalBack($data);
    }


    /**
     * 模拟订单过期
     */
    public function testExpireOrder(){
        $data['order_id']="132132132141242141423123";
        $this->dispatch->methond('DaDa')->test->expireOrder($data);
    }

    /////正式接口

    /**
     * 查询订单详情
     */
    public function testQueryOrder(){
        $data['order_id']="DaDa20191118161510300574";
        $this->dispatch->methond('DaDa')->queryOrder($data);
    }
    /**
     * 重发订单
     */
    public function testReAddOrder(){
        $data['shop_no'] = 11047059;
        $data['origin_id'] = "132132132141242141423123";
        $data['city_code'] = "029";
        $data['cargo_price'] = "11.2";
        $data['is_prepay'] = 0;
        $data['expected_fetch_time'] = time() + 3600;
        $data['receiver_name'] = "测试达达";
        $data['receiver_address'] = "上海市崇明岛";
        $data['receiver_phone'] = "11111111111";
        $data['receiver_lat'] = 31.63;
        $data['receiver_lng'] = 121.41;
        $data['callback'] = "http://test.agoni.com/web/index.php?r=api/delivery/delivery-call-back/index";
        $this->dispatch->methond('DaDa')->reAddOrder($data);
    }

    /**
     * 查询订单运费接口 也称为 订单预发布
     */
    public function testQueryDeliverFee(){
        $data['shop_no'] = 11047059;
        $data['origin_id'] = "544444444444333";
        $data['city_code'] = "010";
        $data['cargo_price'] = "0.01";
        $data['is_prepay'] = 0;
        $data['expected_fetch_time'] = time() + 3600;
        $data['receiver_name'] = "测试达达";
        $data['receiver_address'] = "北京";
        $data['receiver_phone'] = "11111111111";
        $data['callback'] = "http://test.agoni.com/web/index.php?r=api/delivery/delivery-call-back/index";
        $this->dispatch->methond('DaDa')->queryDeliverFee($data);
        $this->assertTrue(true);
    }
    //预发布后进行正式发布
    public function testAddAfterQuery(){
        $data['deliveryNo']='Dada769caf304881495098c21785f8ae581a';
        $this->dispatch->methond('DaDa')->addAfterQuery($data);
    }
    /**
     * 取消订单
     */
    public function testFormalCancel(){
        $data['order_id'] = "132132132141242141423123";
        $data['cancel_reason_id'] = '10000';
        $data['cancel_reason'] = "1111";
        $this->dispatch->methond('DaDa')->formalCancel($data);
    }

    /**
     * 获取取消订单原因的列表
     */
    public function testCancelReasons(){
        $this->dispatch->methond('DaDa')->cancelReasons();
    }
    public function testGetCity(){
        $this->dispatch->methond( 'DaDa')->getCityList();
    }

    ///商户管理

    /**
     * 新增门店
     */
    public function testAddShop(){

        $data['origin_shop_id'] = 'shop001';
        $data['station_name'] = '店';
        $data['business'] = 1;
        $data['city_name'] = '上海';
        $data['area_name'] = '浦东新区';
        $data['station_address'] = '地址1';
        $data['lng'] = '= 31.63';
        $data['lat'] = '22.33';
        $data['contact_name'] = '杨先生';
        $data['phone'] = '13012345678';
        $data['username'] = '13012345678';
        $data['password'] = '123456';

        $result[0]=$data;
        $data1['origin_shop_id'] = 'shop002';
        $data1['station_name'] = '店';
        $data1['business'] = 12;
        $data1['city_name'] = '上海1';
        $data1['area_name'] = '浦东新区1';
        $data1['station_address'] = '地址1';
        $data1['lng'] = '= 31.22';
        $data1['lat'] = '22.33';
        $data1['contact_name'] = '杨先生';
        $data1['phone'] = '13012345678';
        $data1['username'] = '13012345678';
        $data1['password'] = '123456';
        $result[1]=$data1;

        $this->dispatch->methond('DaDa')->addShop($result);
    }
}